<?php

namespace addons\travel\controller;


use addons\travel\controller\Base;
use think\Db;

class Order extends Base
{

    protected $noNeedLogin = [''];
    protected $noNeedRight = ['*'];

    /**
     * 订单列表
     */
    public function index()
    {
        $params = $this->request->get();

        $this->success('订单列表', \addons\travel\model\Order::getList($params));
    }
    /**
     * 订单详情
     */
    public function detail()
    {
        $params = $this->request->get();
        $this->success('订单详情', \addons\travel\model\Order::detail($params));
    }

    /**
     * 预算订单
     */
    public function pre()
    {
        $params = $this->request->post();
        $lang_slug=$this->langSlug;
        $params['lang_slug']=$lang_slug;
        // 表单验证
        $this->sumValidate($params, get_class(), 'pre');

        $result = \addons\travel\model\Order::pre($params);

        if (isset($result['msg']) && $result['msg']) {
            $this->error($result['msg'], $result);
        } else {
            $this->success('计算成功', $result);
        }
    }
    /**
     * 创建订单
     */
    public function createOrder()
    {
        $params = $this->request->post();
        $lang_slug=$this->langSlug;
        $params['lang_slug']=$lang_slug;
        // 表单验证
        $this->sumValidate($params, get_class(), 'createOrder');
        try {
            $order = \addons\travel\model\Order::createOrder($params);
        }catch (\Exception $e) {
            $this->error(__($e->getMessage()));
        }

        $this->success('订单添加成功', $order);
    }


    // 取消订单
    public function cancel()
    {
        $params = $this->request->post();

        // 表单验证
        $this->sumValidate($params, get_class(), 'cancel');

        $this->success('取消成功', \addons\travel\model\Order::operCancel($params));
    }
}
